﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace TreeDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //int[] input = { 10, 20, 12, 15, 26, 5, 3, 9 };
            int[] input = { 15, 7, 18, 11 , 16, 40, 17 };
            //int[] input = { 11, 23, 13, 40, 15, 16, 7, 81, 19, 10, 22, 76, 23, 58, 81, 2, 32, 99 };

            //AVLTree tree = new AVLTree(input);
            
            BinarySearchTree tree = new BinarySearchTree(input);
            TreeHelper.PrintTree(tree.rootNode);
            //TreeHelper.printNthNode(tree.rootNode, 56);
            //tree.LeftMost(tree.rootNode, 18);
            //tree.Remove(3);
            //TreeHelper.ReplaceWithSum(tree.rootNode);

            //Console.WriteLine("Distance: " + TreeHelper.FindDistanceFromRootNode(TreeHelper.FindFirstCommonAncestor(tree.rootNode,2, 4), 2, 4));

            //TreeHelper.PrintTree(tree.rootNode);

            

            //List<List<BinarySearchTreeNode>> nodeListCollection = TreeHelper.CreateDepthWiseLists(tree.rootNode);
            TreeHelper.PrintAllPaths(tree.rootNode);

            //BinarySearchTreeNode mirrorRootNode = TreeHelper.CreateMirror(tree.rootNode);

            //Console.WriteLine("Is tree balanced: " + TreeHelper.IsTreeBalanced(tree.rootNode));

            //TreeHelper.PrintTree(mirrorRootNode);       

            //BinarySearchTreeNode ancestorNode = TreeHelper.FindFirstCommonAncestor(tree.rootNode, 3, 7);
            //while (true)
            //{
            //    int number = Convert.ToInt32(Console.ReadLine());
            //    if (number == 0) break;

            //    //BinarySearchTreeNode nearestNode = TreeHelper.FindNearestNode(tree.rootNode, null, number);
            //    TreeHelper.AllPathsToGivenValue(tree.rootNode, number, 0, new ArrayList());
            //    //Console.WriteLine("Nearest Node: " + nearestNode.data);
            //}
            Console.ReadKey();
        }
    }        
}
